<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Catalog
 *
 * @author admin
 */
class catalog extends CI_Model {

    private $_table_prefix = 'vpc_catalog_prefix';
    private $_table_province = 'vpc_catalog_province';
    private $_table_status = 'vpc_catalog_status';
    private $_table_truck = 'vpc_catalog_truck';
    private $_table_autopart = 'vpc_catalog_autopart';

    public function list_prefix() {
        $query = $this->db->get_where($this->_table_prefix);
        $arr_prefix = array();
        $arr_prefix[''] = 'เลือก';
        foreach ($query->result() as $list) {
            $arr_prefix[$list->id] = $list->prefix_name;
        }
        return $arr_prefix;
    }

    public function list_province() {
        $query = $this->db->get_where($this->_table_province);
        $arr_province = array();
        $arr_province[''] = 'เลือก';
        foreach ($query->result() as $list) {
            $arr_province[$list->id] = $list->province_name;
        }
        return $arr_province;
    }

    public function list_driver_status() {
        $query = $this->db->get_where($this->_table_status, array('parent_id' => 1));
        $arr_status = array();
        $arr_status[''] = 'เลือก';
        foreach ($query->result() as $list) {
            $arr_status[$list->id] = $list->status_name;
        }
        return $arr_status;
    }

    public function list_repair_type() {
        $query = $this->db->get_where($this->_table_status, array('parent_id' => 4));
        $arr_status = array();
        $arr_status[''] = 'เลือก';
        foreach ($query->result() as $list) {
            $arr_status[$list->id] = $list->status_name;
        }
        return $arr_status;
    }

    public function list_truck_model($id = 0) {
        $query = $this->db->get_where($this->_table_truck, array('parent_id' => $id));
        $arr_model = array();
        $arr_model[''] = 'เลือก';
        foreach ($query->result() as $list) {
            $arr_model[$list->id] = $list->name;
        }
        return $arr_model;
    }

    public function list_truck_brand() {
        $query = $this->db->get_where($this->_table_truck, array('parent_id' => NULL));
        $arr_brand = array();
        $arr_brand[''] = 'เลือก';
        foreach ($query->result() as $list) {
            $arr_brand[$list->id] = $list->name;
        }
        return $arr_brand;
    }

    public function list_stock_main_type() {
        $query = $this->db->get_where($this->_table_autopart, array('parent_id' => NULL));
        $arr_main = array();
        $arr_main[''] = 'เลือก';
        foreach ($query->result() as $list) {
            $arr_main[$list->id] = $list->name;
        }
        return $arr_main;
    }

    public function list_stock_sub_type($id = 0) {
        $query = $this->db->get_where($this->_table_autopart, array('parent_id' => $id));
        $arr_sub = array();
        $arr_sub[''] = 'เลือก';
        foreach ($query->result() as $list) {
            $arr_sub[$list->id] = $list->name;
        }
        return $arr_sub;
    }

    public function list_stock_brand($id = 0) {
        $query = $this->db->get_where($this->_table_autopart, array('parent_id' => $id));
        $arr_brand = array();
        $arr_brand[''] = 'เลือก';
        foreach ($query->result() as $list) {
            $arr_brand[$list->id] = $list->name;
        }
        return $arr_brand;
    }

}
